package com.example.demo.basic;

/**
 * 类描述: 用于维护线程的当前数据源；
 *
 * @auth zhanglei
 * @date 2019/3/8 9:06
 **/
public class DataBaseContextHolder {
    //ThreadLocal为弱引用，用完还是要调用remove方法
    private static final ThreadLocal<Integer> dbHolder = new ThreadLocal<Integer>();
    private static final ThreadLocal<Integer> tableHolder = new ThreadLocal<Integer>();


    public static void setDBID(Integer dbID) {
        dbHolder.set(dbID);
    }

    public static Integer getDBID() {
        return dbHolder.get();
    }

    public static void setTableID(Integer tableID) {
        tableHolder.set(tableID);
    }

    public static Integer getTableID() {

        return tableHolder.get();
    }

    public static void clear() {

        dbHolder.remove();
        tableHolder.remove();
    }
}
